#pragma once
#include "../Common/Common.h"
#include "../Common/ArrayBuffer.h"

#define MAX_PACKAGE_LEN 65533
#define SIZE_LENGTH 2
#define CMD_LENGTH 2

#define CMD_REQUEST 1
#define CMD_RESPONE 2
#define CMD_PUSH	3
#define CMD_PING 4

struct PacketHead
{
	PacketHead(void) : size(0), cmd(0)
	{}

	PacketHead(uint16 s, uint16 c) : size(s), cmd(c)
	{}


	uint16 size;
	uint16 cmd;
};

struct RequestHead
{
	RequestHead(void) : method(-1)
	{}

	explicit RequestHead(int m) : method(m)
	{}


	int method;
	//uint32 serial;
};

struct ResponseHead
{
	ResponseHead(void) : method(-1)
	{}

	explicit ResponseHead(int m) : method(m)
	{}


	int method;
	//uint32 serial;
};

inline
ArrayBuffer& operator << (ArrayBuffer& ob, const PacketHead& value)
{
	ob.write(value.size);
	ob.write(value.cmd);
	return ob;
}

inline
ArrayBuffer& operator << (ArrayBuffer& ob, const RequestHead& value)
{
	ob.write(value.method);
	return ob;
}

inline
ArrayBuffer& operator << (ArrayBuffer& ob, const ResponseHead& value)
{
	ob.write(value.method);
	return ob;
}

inline
ArrayBuffer& operator >> (ArrayBuffer& ob, PacketHead& value)
{
	ob.read(value.size);
	ob.read(value.cmd);
	return ob;
}

inline
ArrayBuffer& operator >> (ArrayBuffer& ob, RequestHead& value)
{
	ob.read(value.method);
	return ob;
}

inline
ArrayBuffer& operator >> (ArrayBuffer& ob, ResponseHead& value)
{
	ob.read(value.method);
	return ob;
}
